local ma__fadao = fk.CreateSkill{
  name = "ma__fadao",
}

Fk:loadTranslationTable{
  ["ma__fadao"] = "法道",
  [":ma__fadao"] = "结束阶段，或当一名角色受到属性伤害后，你可以判定，若结果为♠，则你可以对一名其他角色造成1点雷电伤害，否则你获得判定牌并回复1点体力。",

  ["#ma__fadao-choose"] = "法道：你可以对一名角色造成1点雷电伤害",
  --["#ma__fadao-get"] = "法道：你获得判定牌并回复1点体力",

  ["$ma__fadao1"] = "",
  ["$ma__fadao2"] = "",
}

local spec = {
  on_cost = function (self, event, target, player, data)
        return player.room:askToSkillInvoke(player, {
      skill_name = ma__fadao.name,
    })
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local judge = {
      who = player,
      reason = ma__fadao.name,
      pattern = ".|.|spade",
      extra_data = {
        fadaoSource = player,
      }
    }
    room:judge(judge)
    if target.dead then return end
    if judge:matchPattern() then
      if player.dead then return end
      local to = room:askToChoosePlayers(player, {
      targets = room:getOtherPlayers(player, false),
      min_num = 1,
      max_num = 1,
      prompt = "#ma__fadao-choose",
      skill_name = ma__fadao.name,
      cancelable = true,
    })
    if #to > 0 then
      room:damage{
        from = player,
        to = to[1],
        damage = 1,
        damageType = fk.ThunderDamage,
        skillName = ma__fadao.name,
      }
    end
    end
  end,
}

ma__fadao:addEffect(fk.FinishJudge, {
  mute = true,
  can_trigger = function (self, event, target, player, data)
    return data.extra_data and data.extra_data.fadaoSource == player and
      player.room:getCardArea(data.card) == Card.Processing and not player.dead and data.card.suit ~= Card.Spade
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    player.room:obtainCard(player, data.card, true, fk.ReasonJustMove)
    if player:isWounded() then
      player.room:recover{
        who = player,
        num = 1,
        recoverBy = player,
        skillName = ma__fadao.name,
      }
    end
  end,
})

ma__fadao:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(ma__fadao.name) and player.phase == Player.Finish
  end,
  on_cost = spec.on_cost,
  on_use = spec.on_use,
})
ma__fadao:addEffect(fk.Damaged, {
  anim_type = "masochism",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(ma__fadao.name) and data.damageType ~= fk.NormalDamage
  end,
  on_cost = spec.on_cost,
  on_use = spec.on_use,
})


return ma__fadao